<?php if(!defined('WDK_PATH')) exit('No direct script access allowed');
class Hp_Ftp
{
	private 
		$host	= 'localhost'	,
		$port	= 21			,
		$id		= ''			,
		$pwd	= ''			,
		$conn	= null			;
	
	
	function __construct()
	{
		$this->conn = null;
	}
	
	public function login($host='localhost', $id='', $pwd='', $port=21)
	{
		$this->end();
		$this->host	= $host;
		$this->id	= $id;
		$this->pwd	= $pwd;
		$this->port	= $port;
		$this->conn = ftp_connect($this->host, $this->port);
		ftp_login($this->conn, $this->id, $this->pwd);
	}
	
	public function put($local_file='', $remote_path='')
	{
		if($this->conn != null)
		{
			ftp_put($this->conn, $remote_path.'/'.basename($local_file), $local_file, FTP_BINARY);
		}
	}
	
	public function get($remote_file='', $local_path='')
	{
		if($this->conn != null)
		{
			ftp_pasv($this->conn, TRUE);
			ftp_chdir($this->conn, dirname($remote_file));
			ftp_get($this->conn, $local_path.'/'.basename($remote_file), basename($remote_file), FTP_BINARY);
		}
	}
	
	public function remove($remote_file='')
	{
		if($this->conn != null)
		{
			ftp_pasv($this->conn, TRUE);
			ftp_delete($this->conn, $remote_file);
		}
	}
	
	public function end()
	{
		if($this->conn != null)
		{
			ftp_close($this->conn);
			$this->conn = null;			
		}
	}
}